import { setDocumentTitle } from "@/utils"
import { createRouter, createWebHashHistory } from "vue-router"
import { useAuthStore } from "@/store/auth"
import { routes } from "./router"

const router = createRouter({
  history:createWebHashHistory(import.meta.env.VITE_PUBLIC_PATH), //env.d.ts文件的配置
  routes,
  scrollBehavior:() =>({ left:0,top:0 })
})

router.beforeEach((to, from, next) => {
  //获取标题
  setDocumentTitle(to.meta.title as string)
  //获取AppID进行存储
  const authStore = useAuthStore()
  const AppID = 'wx9790364d20b47d95'
  if(AppID){
    authStore.setAppId(AppID)
  }

  // 微信浏览器内微信授权登陆
	// if (isWeChat()) {
	// 	if (code) {
	// 		authStore.setIsAuth(true)
	// 		authStore.setCode(code)
	// 	}
	// 	if (!authStore.isAuth) {
	// 		location.href = fetchWeChatAuth()
	// 	}
	// }
  next()
  
})

router.afterEach( route => {
  
  
})

export default router